package com.it.service.impl;

import cn.hutool.core.date.DateUtil;
import com.it.dao.LogDao;
import com.it.entity.Log;
import com.it.entity.LogAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class LogServiceimpl implements com.it.service.LogService {
    @Autowired
    LogDao log;

    /**
     * 查询某个点
     * @param usid
     * @return
     */
    @Override
    public List seal(int usid) {
       List lis= log.seal(usid);
        return lis;
    }

    /**
     * 查询某个点上的信息
     * @param lg
     * @return
     */
    @Override
    public List seconfig(Log lg) {
        List lis=log.seconfig(lg);
        List list=zhuan(lis);
        return list;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public int del(int id) {
        int desu=log.del(id);
        return desu;
    }

    /**
     * 添加
     * @param lo
     * @return
     */
    @Override
    public int addlog(Log lo) {
        int upcg=log.addlog(lo);
        return upcg;
    }

    public List zhuan(List lis){
        List<LogAll> lo=new ArrayList<LogAll>();
        int id;
        int usid;
        String logtime;
        String context;
        int location;
        for(int i=0;i<lis.size();i++){
            Log ylo= (Log) lis.get(i);
            id=ylo.getId();
            usid=ylo.getUsid();
            String formatDate = DateUtil.formatDate(ylo.getLogtime());
            String bmo=formatDate.substring(5,7);
            String bday=formatDate.substring(8,10);
            logtime=bmo+"月"+bday+"日";
            context=ylo.getContext();
            location=ylo.getLocation();
            LogAll loa=new LogAll(id,usid,logtime,context,location);
            lo.add(loa);
        }
        return  lo;
    }
}
